import store from '@/store'
export default {
  bind(el, binding, vnode) {
    const { power } = binding.value
    const { assignment } = store.getters
    if (power && Array.isArray(assignment) && assignment.length > 0) {
      const powerful = assignment.some(function(role) {
        return role.includes(power)
      })
      // console.log(powerful)
      if (!powerful) {
        // 暂时页面级控制，有风险，removedom操作太费劲，待定吧
        // el.parentNode && el.parentNode.removeChild(el)
        el.style.display = 'none'
      } else {
        el.style.display = 'inline-block'
      }
    }
  },
  update(el, binding, vnode) {
    const { power } = binding.value
    const { assignment } = store.getters
    if (power && Array.isArray(assignment) && assignment.length > 0) {
      const powerful = assignment.some(function(role) {
        return role.includes(power)
      })
      // console.log(powerful)
      if (!powerful) {
        // 暂时页面级控制，有风险，removedom操作太费劲，待定吧
        // el.parentNode && el.parentNode.removeChild(el)
        el.style.display = 'none'
      } else {
        el.style.display = 'inline-block'
      }
    }
  }
}
